package com.example.himalayaproject.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.himalayaproject.R;
import com.example.himalayaproject.download.DowLoadingFragment;
import com.example.himalayaproject.download.DowSpecialFragment;
import com.example.himalayaproject.download.DowVoiceFragment;
import com.example.himalayaproject.adapter.FindViewpagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DownloadFragment extends Fragment {

    public DownloadFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_download, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        aboutTabLayout(view);
    }
    private void aboutTabLayout(View view) {
        ViewPager pager = (ViewPager) view.findViewById(R.id.download_fragment_viewpager);
        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.download_fragment_tablayout);
        List<String> list = new ArrayList<>();
        list.add("专辑");
        list.add("声音");
        list.add("下载");
         List<Fragment> fragments = new ArrayList<>();
        DowLoadingFragment dowLoadingFragment = new DowLoadingFragment();
        DowSpecialFragment dowSpecialFragment = new DowSpecialFragment();
        DowVoiceFragment dowVoiceFragment = new DowVoiceFragment();
        fragments.add(dowLoadingFragment);
        fragments.add(dowSpecialFragment);
        fragments.add(dowVoiceFragment);

       FindViewpagerAdapter findViewpagerAdapter =  new FindViewpagerAdapter(getChildFragmentManager(),list,fragments);
        pager.setOffscreenPageLimit(3);
        pager.setAdapter(findViewpagerAdapter);
        tabLayout.setupWithViewPager(pager);
    }
}
